package cn.edu.example.web.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import cn.edu.example.po.Place;
import cn.edu.example.service.PlaceService;
@Controller
public class PlaceController {
 
	
	@Autowired
	private PlaceService placeService;
	
	
	@RequestMapping(value = "/place/getAllplace.action", method = RequestMethod.GET)
	public String getPlaceList(Model model) {
		
		List plist=placeService.getPlaceList();//浠巗ervices鑾峰彇鏁版嵁
		model.addAttribute("Place_list",plist);
		return "place";//鎺у埗灞傝烦杞埌jsp
	}
	//绠＄悊鍛樺垹闄や功绫�
	@RequestMapping("/place/delPlace.action")
	@ResponseBody
	public String placeDelete(String placename) {
		int rows = placeService.delPlace(placename);
		if(rows > 0){			
	        return "OK";
	    }else{
	        return "FAIL";			
	    }
	}
	
	//绠＄悊鍛樻坊鍔犱功绫嶄俊鎭�
	@RequestMapping("/place/create.action")
	@ResponseBody
	public String placeCreate(Place place,HttpSession session) {

	    // 鎵цService灞備腑鐨勫垱寤烘柟娉曪紝杩斿洖鐨勬槸鍙楀奖鍝嶇殑琛屾暟
	    int rows = placeService.createPlace(place);
	    if(rows > 0){
	        return "OK";
	    }else{
	        return "FAIL";
	    }
	}
	
	
	// 绠＄悊鍛橀�氳繃id鑾峰彇鐢ㄦ埛淇℃伅
	@RequestMapping("place/getPlaceById.action")
	@ResponseBody
	public Place getPlaceById(Integer place_id) {	 
	   Place place = placeService.getPlaceById(place_id);
	    return place;
	}
	
	//绠＄悊鍛樻洿鏂拌绋嬩俊鎭�
	@RequestMapping("/place/update.action")
	@ResponseBody
	public String placeUpdate(Place place) {
	    int rows = placeService.updatePlace(place);
	    if(rows > 0){
	        return "OK";
	    }else{
	        return "FAIL";
	    }
	}
	
	//绠＄悊鍛樻煡鎵惧満鍦�
	@RequestMapping(value = "/place/findplace.action", method = RequestMethod.GET)
	public String getfindPlaceList(String name,Model model) {	
		List list=placeService.getfindPlaceList(name);//浠巗ervices鑾峰彇鏁版嵁
		model.addAttribute("place_name",name); 
		model.addAttribute("Place_list",list);
	    return "place";//鎺у埗灞傝烦杞埌jsp
	}
}
